<?php
namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class RegistrActivityUser extends Model
{

    use SoftDelete;

    // 表名
    protected $name = 'registr_activity_user';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'sex_text', 'gender_text', 'education_text', 'cognitive_approach_text', 'Is_voter_text',
    ];

    public function getSexList()
    {
        return ['1' => __('男'), '2' => __('女')];
    }

    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list  = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getIsVoterList()
    {
        return ['1' => __('是'), '2' => __('否')];
    }
  

    public function consultationcategory()
    {
        return $this->belongsTo('ActivityRegisterCategory', 'consultation_type', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function getIsVoterTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_voter']) ? $data['is_voter'] : '');
        $list  = $this->getIsVoterList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getGenderList()
    {
        return ['1' => __('男'), '2' => __('女')];
    }

    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list  = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCognitiveApproachList()
    {
        return ['1' => __('報紙雜誌'), '2' => __('地區辦事處'), '3' => __('工會會員'), '4' => __('工聯會'), '5' => __('內地政府部門'), '6' => __('朋友介紹'), '7' => __('網路'), '8' => __('香港政府部門'), '9' => __('宣傳品'), '10' => __('已登記人員'), '11' => __('議員辦事處')];
    }

    public function getCognitiveApproachTextAttr($value, $data)
    {
       // $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list  = $this->getCognitiveApproachList();
        if($value==''||$value==null){
            return '';
        }
       // print_r($value);exit;
        return isset($list[$data['cognitive_approach']]) ? $list[$data['cognitive_approach']] : '';
    }

    public function getEducationList()
    {
        return ['1' => __('小學以下'), '2' => __('小學'), '3' => __('中學'), '4' => __('大專或以上')];
    }

    public function getEducationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['education']) ? $data['education'] : '');
        $list  = $this->getEducationList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function registractivity()
    {
        return $this->belongsTo('RegistrActivity', 'registr_activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
